//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using DotNetNuke.Modules.NavigationProvider;
using DotNetNuke.UI.WebControls;
namespace DotNetNuke.UI.Skins.Controls
{
	partial class Nav : UI.Skins.NavObjectBase
	{

		private void InitializeComponent()
		{
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			try
			{
				bool blnIndicateChildren = bool.Parse(GetValue(this.IndicateChildren, "True"));
				string strRightArrow;
				string strDownArrow;
				UI.Skins.SkinController objSkins = new UI.Skins.SkinController();
				if (!String.IsNullOrEmpty(IndicateChildImageSub))
				{
					strRightArrow = IndicateChildImageSub;
				}
				else
				{
					strRightArrow = "breadcrumb.gif";
				}
				if (!String.IsNullOrEmpty(IndicateChildImageRoot))
				{
					strDownArrow = IndicateChildImageRoot;
				}
				else
				{
					strDownArrow = "menu_down.gif";
				}
				if (!String.IsNullOrEmpty(SeparatorHTML))
				{
					SeparatorHTML = FixImagePath(SeparatorHTML);
				}
				if (!String.IsNullOrEmpty(SeparatorLeftHTML))
				{
					SeparatorLeftHTML = FixImagePath(SeparatorLeftHTML);
				}
				if (!String.IsNullOrEmpty(SeparatorRightHTML))
				{
					SeparatorRightHTML = FixImagePath(SeparatorRightHTML);
				}
				if (!String.IsNullOrEmpty(SeparatorLeftHTMLBreadCrumb))
				{
					SeparatorLeftHTMLBreadCrumb = FixImagePath(SeparatorLeftHTMLBreadCrumb);
				}
				if (!String.IsNullOrEmpty(SeparatorRightHTMLBreadCrumb))
				{
					SeparatorRightHTMLBreadCrumb = FixImagePath(SeparatorRightHTMLBreadCrumb);
				}
				if (!String.IsNullOrEmpty(SeparatorLeftHTMLActive))
				{
					SeparatorLeftHTMLActive = FixImagePath(SeparatorLeftHTMLActive);
				}
				if (!String.IsNullOrEmpty(SeparatorRightHTMLActive))
				{
					SeparatorRightHTMLActive = FixImagePath(SeparatorRightHTMLActive);
				}
				if (!String.IsNullOrEmpty(NodeLeftHTMLBreadCrumbRoot))
				{
					NodeLeftHTMLBreadCrumbRoot = FixImagePath(NodeLeftHTMLBreadCrumbRoot);
				}
				if (!String.IsNullOrEmpty(NodeRightHTMLBreadCrumbRoot))
				{
					NodeRightHTMLBreadCrumbRoot = FixImagePath(NodeRightHTMLBreadCrumbRoot);
				}
				if (!String.IsNullOrEmpty(NodeLeftHTMLBreadCrumbSub))
				{
					NodeLeftHTMLBreadCrumbSub = FixImagePath(NodeLeftHTMLBreadCrumbSub);
				}
				if (!String.IsNullOrEmpty(NodeRightHTMLBreadCrumbSub))
				{
					NodeRightHTMLBreadCrumbSub = FixImagePath(NodeRightHTMLBreadCrumbSub);
				}
				if (!String.IsNullOrEmpty(NodeLeftHTMLRoot))
				{
					NodeLeftHTMLRoot = FixImagePath(NodeLeftHTMLRoot);
				}
				if (!String.IsNullOrEmpty(NodeRightHTMLRoot))
				{
					NodeRightHTMLRoot = FixImagePath(NodeRightHTMLRoot);
				}
				if (!String.IsNullOrEmpty(NodeLeftHTMLSub))
				{
					NodeLeftHTMLSub = FixImagePath(NodeLeftHTMLSub);
				}
				if (!String.IsNullOrEmpty(NodeRightHTMLSub))
				{
					NodeRightHTMLSub = FixImagePath(NodeRightHTMLSub);
				}
				if (String.IsNullOrEmpty(this.PathImage))
				{
					this.PathImage = PortalSettings.HomeDirectory;
				}
				if (blnIndicateChildren)
				{
					this.IndicateChildImageSub = strRightArrow;
					if (this.ControlOrientation.ToLower() == "vertical")
					{
						this.IndicateChildImageRoot = strRightArrow;
					}
					else
					{
						this.IndicateChildImageRoot = strDownArrow;
					}
				}
				else
				{
					this.IndicateChildImageSub = "[APPIMAGEPATH]spacer.gif";
				}
				this.PathSystemScript = Common.Globals.ApplicationPath + "/controls/SolpartMenu/";
				this.PathSystemImage = "[APPIMAGEPATH]";
				BuildNodes(null);
			}
			catch (Exception exc)
			{
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		private string FixImagePath(string strPath)
		{
			if (strPath.IndexOf("src=") != -1 && strPath.IndexOf("src=\"/") < 0)
			{
				return strPath.Replace("src=\"", "src=\"[SKINPATH]");
			}
			else
			{
				return strPath;
			}
		}
		private void BuildNodes(WebControls.DNNNode objNode)
		{
			DNNNodeCollection objNodes;
			objNodes = GetNavigationNodes(objNode);
			this.Control.ClearNodes();
			this.Bind(objNodes);
		}
		protected override void OnInit(System.EventArgs e)
		{
			InitializeNavControl(this, "SolpartMenuNavigationProvider");
			Control.NodeClick += new DotNetNuke.Modules.NavigationProvider.NavigationProvider.NodeClickEventHandler(Control_NodeClick);
			Control.PopulateOnDemand += new NavigationProvider.PopulateOnDemandEventHandler(Control_PopulateOnDemand);
			base.OnInit(e);
			InitializeComponent();
		}
		private void Control_NodeClick(NavigationEventArgs args)
		{
			if (args.Node == null)
			{
				args.Node = Navigation.GetNavigationNode(args.ID, Control.ID);
			}
			Response.Redirect(Common.Globals.ApplicationURL(int.Parse(args.Node.Key)), true);
		}
		private void Control_PopulateOnDemand(NavigationEventArgs args)
		{
			if (args.Node == null)
			{
				args.Node = Navigation.GetNavigationNode(args.ID, Control.ID);
			}
			BuildNodes(args.Node);
		}
	}
}
